home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 4
/
CDPD_IV.bin
/
e
/
mailinglists
/
amigae.0993sept.archive
/
000018_crash!axion.bt.…uk!D.Higginson_Mon, 6 Sep 93 02:17:59 PST.msg
< prev
next >
Wrap
Internet Message Format
|
1994-05-26
|
6KB
Received: by bkhouse.cts.com (V1.16/Amiga)
id AA00000; Mon, 6 Sep 93 02:17:59 PST
Received: from zaphod.axion.bt.co.uk by crash.cts.com with smtp
(Smail3.1.28.1 #18) id m0oZc73-0000fbC; Mon, 6 Sep 93 01:39 PDT
Received: from elephant.axion.bt.co.uk by zaphod.axion.bt.co.uk with SMTP (PP); Mon, 6 Sep 1993 09:39:33 +0100
Message-Id: <m0oZc73-0000fbC@crash.cts.com>
Date: Mon, 06 Sep 93 09:39:31 BST
From: D.Higginson@axion.bt.co.uk
To: AmigaE@bkhouse.cts.com
Subject: Scrolly Routine!
Hi all,
This program is a scroll routine which makes a horizontally
scrolling pattern. It could be used as the basis for a
horizontal shoot-'em-up.
How it works:
First, I set up a 784x200 low-res screen. This is more than
twice the width of a normal low-res screen, and is NTSC so
that all can use this example straight off.
There are 4 images, one blank and three differently coloured
images. The data are those hexadecimal numbers - stored one
bitplane at a time (two bitplanes). The images displayed in
the demo are decided at random, but it would be easy to get
the program to read this data from memory to produce a game.
Each VBL (vertical blank), one image is pasted just to the
right of the visible area and one just to the left. This
continues until that column is full of images. Pasting of the
next row then starts after 4 VBLs because the images are 16
pixels wide and the screen is only 12 blocks tall.
Each VBL the screen is shifted one pixel to the left using
the ScrollVPort() function. This does not move any graphics
data, it simply shifts the view that you have onto the
screen's bitmap.
When a full screen has been built up, there is already a
copy of the image because of the blocks that were pasted to
the left of the visible portion. This means the screen can
be flicked back and the whole process starts again.
The result is a very fast scroll routine, which is silky
smooth even under Intuition (!). The only CPU time used each
VBL is the time to paste one 16x16 image, making it feasible
to produce a game based on many bitplanes. The variable
SCROLLSPEED can be used to increase the speed of the scroll.
Set it to 1, 2, 4 or 8 for best effects. This also signifies
the number of 16x16 images drawn per VBL.
Although this example only works under KickStart 2.0+, it
could be modified for earlier OS versions.
Enjoy!
Dave.
------8<------8<------8<------8<------
MODULE 'exec/memory',
'intuition/intuition','intuition/screens',
'graphics/text','graphics/view'
CONST NUMIMAGE=4,IMAGEDATASIZE=2*16*2,SCROLLSPEED=1
ENUM ER_NONE,ER_NOSCRN,ER_NOMEM
DEF s=NIL,w=NIL:PTR TO window,sprite=NIL,imagedata=NIL
PROC setupimages()
IF (imagedata:=AllocVec(NUMIMAGE*IMAGEDATASIZE,
MEMF_CHIP OR MEMF_CLEAR))=NIL THEN Raise(ER_NOMEM)
CopyMemQuick([$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
$FFFF,$FFFF,$C003,$C003,$C003,$C003,$C3C3,$C3C3,
$C3C3,$C3C3,$C003,$C003,$C003,$C003,$FFFF,$FFFF,
$0000,$0000,$0000,$0000,$0000,$0000,$03C0,$03C0,
$03C0,$03C0,$0000,$0000,$0000,$0000,$0000,$0000,
$0000,$0000,$0000,$0000,$0000,$0000,$03C0,$03C0,
$03C0,$03C0,$0000,$0000,$0000,$0000,$0000,$0000,
$FFFF,$FFFF,$C003,$C003,$C003,$C003,$C003,$C003,
$C003,$C003,$C003,$C003,$C003,$C003,$FFFF,$FFFF,
$FFFF,$FFFF,$C003,$C003,$C003,$C003,$C003,$C003,
$C003,$C003,$C003,$C003,$C003,$C003,$FFFF,$FFFF,
$FFFF,$FFFF,$C003,$C003,$C003,$C003,$C3C3,$C3C3,
$C3C3,$C3C3,$C003,$C003,$C003,$C003,$FFFF,$FFFF]:INT,
imagedata,NUMIMAGE*IMAGEDATASIZE)
ENDPROC
PROC setupscreen()
CloseWorkBench()
IF (s:=OpenScreenTagList(NIL,
[SA_WIDTH,784,SA_HEIGHT,200,SA_DEPTH,2,SA_DISPLAYID,0,
SA_QUIET,TRUE,SA_FONT,['topaz.font',8,0,0]:textattr,
SA_OVERSCAN,OSCAN_TEXT,
0,0]))=NIL THEN Raise(ER_NOSCRN)
IF (w:=OpenWindowTagList(NIL,
[WA_LEFT,0,WA_TOP,0,WA_WIDTH,784,WA_HEIGHT,256,
WA_IDCMP,0,
WA_FLAGS,WFLG_SIMPLE_REFRESH OR WFLG_NOCAREREFRESH OR
WFLG_BORDERLESS OR WFLG_ACTIVATE OR WFLG_RMBTRAP,
WA_CUSTOMSCREEN,s,
WA_MOUSEQUEUE,0,WA_RPTQUEUE,0,
0,0]))=NIL THEN Raise(ER_NOSCRN)
IF sprite:=AllocMem(20,MEMF_CHIP OR MEMF_CLEAR)
SetPointer(w,sprite,1,16,0,0)
ENDIF
LoadRGB4(ViewPortAddress(w),
[$000,$F00,$0F0,$FF0]:INT,16)
ENDPROC
PROC shutdown()
IF w THEN CloseWindow(w)
IF sprite THEN FreeMem(sprite,20)
IF s THEN CloseScreen(s)
IF imagedata THEN FreeVec(imagedata)
OpenWorkBench()
ENDPROC
PROC scroll()
DEF vp:PTR TO viewport,bigx,smallx,tile,imagenum,i,r,ypos
r:=w.rport
vp:=s+44
REPEAT
FOR bigx:=0 TO 384 STEP 16
IF Mouse()
Raise(ER_NONE)
ENDIF
FOR smallx:=0 TO 15 STEP SCROLLSPEED
PutInt(vp.rasinfo+8,32+bigx+smallx)
ScrollVPort(vp)
WaitTOF()
FOR tile:=0 TO SCROLLSPEED-1
IF smallx+tile<12
imagenum:=Rnd(NUMIMAGE)
ypos:=smallx+tile*16
i:=[0,0,16,16,1,imagenum*IMAGEDATASIZE+imagedata,3,0,NIL]:image
DrawImage(r,i,bigx,ypos)
DrawImage(r,i,bigx+400,ypos)
ENDIF
ENDFOR
ENDFOR
ENDFOR
UNTIL FALSE
ENDPROC
PROC main() HANDLE
setupimages()
setupscreen()
scroll()
Raise(ER_NONE)
EXCEPT
shutdown()
IF exception<>ER_NONE THEN WriteF('There was an error.\n')
ENDPROC
------8<------8<------8<------8<------
Apologies for uncommented code (it was late :-)